/**
 * JavaScript debug library.
 * @author shenw
 */
(function(){
	var root = pack("jshen.debug");
	/**
	 *
	 * @param {Object} obj
	 */
	root.method('property', function(obj){
	    var props = "";
	    var i;
	    for (i in obj) {
	        if (obj.hasOwnProperty(i)) {
	            props += i + " = " + obj[i] + "\n";
	        }
	    }
	    alert(props);
	});
	/**
	 * 
	 * @param {Object} level
	 * @param {Object} target
	 */
	root.DivLogger = function(level, target){
	    /**
	     * log level.
	     */
	    this.LEVEL_TRACE = 1;
	    this.LEVEL_DEBUG = 2;
	    this.LEVEL_INFO = 3;
	    this.LEVEL_WARN = 4;
	    this.LEVEL_ERROR = 5;
	    this.LEVEL_FATAL = 6;
	    /**
	     * font colors for each logging level.
	     */
	    this.color = {
	        1: "a0a000",
	        2: "64c864",
	        3: "000000",
	        4: "0000ff",
	        5: "ff8c00",
	        6: "ff0000"
	    };
	    /**
	     * logger title.
	     */
	    this.title = {
	        1: "TRAC",
	        2: "DEBUG",
	        3: "INFO",
	        4: "WARN",
	        5: "ERROR",
	        6: "FATAL"
	    }
	    /**
	     * default log level.
	     */
	    this.logLevel = level || 3;
	    /**
	     * targetDiv is the DIV object to output to.
	     */
	    this.targetDiv = target || null;
	    /**
	     * level setter method.
	     */
	    this.setLevel = function(level){
	        this.logLevel = level;
	        return this;
	    };
	    /**
	     * targetDiv setter method.
	     */
	    this.setTargetDiv = function(target){
	        this.targetDiv = target;
	        this.targetDiv.innerHTML = "";
	        return this;
	    };
	    /**
	     * detect can be logged with input level.
	     */
	    this.shouldBeLogged = function(level){
	        if (level >= this.logLevel) {
	            return true;
	        }
	        else {
	            return false;
	        }
	    };
	    /**
	     * write log message in input level.
	     * @param {Object} level
	     * @param {Object} message
	     */
	    this.log = function(level, message){
	        this.targetDiv.innerHTML += "<div style='color:#" + this.color[level] + ";'>[" +
	        this.title[level] +
	        "] " +
	        message +
	        "</div>";
	    };
	    /**
	     * write log in trace level.
	     */
	    this.trace = function(message){
	        this.log(this.LEVEL_TRACE, message);
	    };
	    /**
	     * write log in debug level.
	     */
	    this.debug = function(message){
	        this.log(this.LEVEL_DEBUG, message);
	    };
	    /**
	     * write log in info level.
	     */
	    this.info = function(message){
	        this.log(this.LEVEL_INFO, message);
	    };
	    /**
	     * write log in warn level.
	     */
	    this.warn = function(message){
	        this.log(this.LEVEL_WARN, message);
	    };
	    /**
	     * write log in error level.
	     */
	    this.error = function(message){
	        this.log(this.LEVEL_ERROR, message);
	    };
	    /**
	     * write log in fatal level.
	     */
	    this.fatal = function(message){
	        this.log(this.LEVEL_FATAL, message);
	    };
	};
})();
